import 'package:flutter/material.dart';

class SwitchDemo extends StatefulWidget {
  const SwitchDemo({super.key});

  @override
  State<SwitchDemo> createState() => _SwitchDemoState();
}

class _SwitchDemoState extends State<SwitchDemo> {
  bool _switchItme = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('SwitchDemo'),
        elevation: 0,
      ),
      body: Container(
        padding: const EdgeInsets.all(16),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SwitchListTile(
              value: _switchItme,
              onChanged: (value) {
                setState(() {
                  _switchItme = value ;
                });
              },
              title: const Text('开关Switch Item A'),
              subtitle: const Text('描述Description'),
              secondary: Icon(_switchItme ? Icons.visibility : Icons.visibility_off),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(_switchItme ? '打开' : '关闭'),
                const SizedBox(width: 10,),
                Switch(
                  value: _switchItme,
                  onChanged: (value) {
                    setState(() {
                      _switchItme = value;
                    });
                  },
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}